package com.java.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 李启旋
 * @create 2023-03-10 11:24
 */
public class UserIdMap {
    private static final ThreadLocal<ArrayList<List<Integer>>> tl = new ThreadLocal<>();

    public static void saveUserId(Integer id){
        ArrayList<List<Integer>> lists = tl.get();
        if (lists == null || lists.isEmpty()){
            lists=new ArrayList<>();
        }
        ArrayList<Integer> list = new ArrayList<>();
        list.add(id);
        lists.add(list);
        tl.set(lists);
    }

    public static List<Integer> getUserMax(){
        ArrayList<List<Integer>> lists = tl.get();
        if (lists == null || lists.isEmpty()){
            return null;
        }else{
            return lists.get(lists.size()-1);
        }
    }

    public static void removeUserMax(){
        ArrayList<List<Integer>> lists = tl.get();
        lists.remove(lists.size()-1);
    }

    public static void saveLists(ArrayList<List<Integer>> lists){
        tl.set(lists);
    }

    public static void saveList(List<Integer> list){
        ArrayList<List<Integer>> lists = new ArrayList<>();
        lists.add(list);
        tl.set(lists);
    }

    public static ArrayList<List<Integer>> getLists(){
        return  tl.get();
    }
}
